clear
%cd ('W:\Projects\Hoffmann_Shcherbakova\Programs_RES')

%Burns-Mitchell Diagram
state_group='all';
s=1; T=42;
Main_preparation

%dc=dc';
%dgsp=dgsp';

  NotYetDeregInRec=(1-Intra).*[NBERTrough(2:T+1)*ones(1,K)];
  AlreadyDeregInRec=Intra.*[NBERTrough(2:T+1)*ones(1,K)];

  clear ny_d* ar_d*
  ny_dc=[];ny_dgsp=[];
  ar_dc=[];ar_dgsp=[];
  for t=1:T;
    ny_ind=find(NotYetDeregInRec(t,:)==1)
    ar_ind=find(AlreadyDeregInRec(t,:)==1);
    if isempty(ny_ind)==0;
        
        ny_dc=[ny_dc;dc(t-1:t+1,ny_ind)'];
        
        ny_dgsp=[ny_dgsp;dgsp(t-1:t+1,ny_ind)'];
    end;
    if isempty(ar_ind)==0;
        
        ar_dc=[ar_dc;dc(t-1:t+1,ar_ind)'];
        
        ar_dgsp=[ar_dgsp;dgsp(t-1:t+1,ar_ind)'];
    end;
  end;
  
  clear b_ny b_ar
  for l=1:size(ar_dgsp,2);
  aux_ny=newols(ny_dc(:,l),[ny_dgsp(:,l),ones(size(ny_dgsp,1),1)]);
  b_ny(l,1)=aux_ny.b(1,1);
  
  aux_ar=newols(ar_dc(:,l),[ar_dgsp(:,l),ones(size(ar_dgsp,1),1)]);
  b_ar(l,1)=aux_ar.b(1,1);
  end;
 
  figure(2)
  plot([0,0],[0,0.4],'k-')
  hold on
  plot([-1,-1;0,0;1,1],[b_ny,b_ar]);
  [b_ny,b_ar]
    
  